package com.itcoon.cloud.framework.mybatis.typehandler;

import com.fasterxml.jackson.core.type.TypeReference;
import com.itcoon.cloud.framework.utils.JsonUtils;

public class TypeReferenceToJsonTypeHandler<T> extends AbstractToStringTypeHandler<T> {

    private final TypeReference<T> typeReference;

    public TypeReferenceToJsonTypeHandler(TypeReference<T> typeReference) {
        this.typeReference = typeReference;
    }


    @Override
    String convertNonNull(T t) {
        return JsonUtils.writeToJson(t);
    }

    @Override
    T reverseNonNullConvert(String column) {
        return JsonUtils.readFromJson(column, typeReference);
    }


}
